<%-- 
    Document   : user
    Created on : Sep 28, 2011, 7:12:32 AM
    Author     : Guan Junming <guan.junming@mabang.net>
--%>
<%@include file="../../WEB-INF/jspf/admin/common.jspf" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>       
        <%@include file="../../WEB-INF/jspf/admin/htmlHeader.jspf"%>
        <title>用户管理</title>
        <script type="text/javascript">
            function showUpdate(key){
                $.getJSON("${adminModule}", {action:"select",id:key}, 
                function(data){      
            <c:forEach var="field" items="${fields}">
                        theForm.elements["${field.get('name')}"].value = data["${field.get('name')}"];
            </c:forEach>                    
                        theForm.elements["action"].value = "update";
                        $('#editor').dialog('open');
                    }
                );}      
        </script>
    </head>
    <body>                
        <table border="1" style="width: 100%">
            <tr><td><button onclick="javascritp:showCreate();">ADD</button></td></tr>
            <c:forEach var="field" items="${fields}">
                <td>${field.get('label')}</td>  
            </c:forEach>    
            <c:forEach var="entity" items="${entities}">
                <tr>
                    <c:forEach var="field" items="${fields}">
                        <c:choose>
                            <c:when test="${field.get('name') == 'picture'}">
                                <td><img src="${entity[field.get('name')]}" width="80px" height="60px"></td>
                                </c:when>                         
                                <c:otherwise>
                                <td>${entity[field.get('name')]}</td>  
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>                    
                    <td><a href="javascript:showUpdate(${entity.id})">修改</a></td>
                    <td><a href="javascript:showDelete('${adminModule}',${entity.id})">删除</a></td>
                </tr>
            </c:forEach>
            <tr><td><button onclick="javascritp:showCreate();">ADD</button></td></tr>
        </table>
        <div id="editor">                     
            <form id="theForm" action="${adminModule}" method="POST" enctype="multipart/form-data">
                <input type="hidden" name="action" value="create"/>
                <input type="hidden" name="id"/>
                <table>
                    <c:forEach var="field" items="${fields}">
                        <c:choose>
                            <c:when test="${field.get('name') == 'id'}"></c:when>
                            <c:when test="${field.get('name') == 'picture'}">
                                <tr>
                                    <td>${field.get('label')}</td>
                                    <td><input type="file" name="${field.get('name')}"/></td>
                                </tr>  
                            </c:when>                      
                            <c:otherwise>
                                <tr>
                                    <td>${field.get('label')}</td><td><input name="${field.get('name')}"/></td>
                                </tr>       
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>                           
                    <tr style="text-align: center"><td colspan="2"><button type="submit">SUBMIT</button></td></tr>
                </table>
            </form>
        </div>
    </body>
</html>
